package com.example.demo.controller;

import com.example.demo.controller.requests.NewOrderRequest;
import com.example.demo.model.Order;
import com.example.demo.service.IDrinkService;
import com.example.demo.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

@Slf4j
//@Controller
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    public OrderService orderService;

    @Autowired
    IDrinkService iDrinkService;

//    新增订单
//    request用于接收参数
    @PostMapping("/")
    public Order addNewOrder(@RequestBody NewOrderRequest request){
        log.info("订单信息：{}",request);
//        要保存的order
        Order order = new Order();
        order.setCreateTime(LocalDate.now());
//        和数据库drink里面的id对应起来

        BeanUtils.copyProperties(request,order);
//        orderService.addNewOrder(order,iDrinkService.getDrinkById());
        order.setCustomer(request.getCustomer());
        return null;
    }


}
